16. Exercise: Click Response and Saving State
Adding a ClickListener and Saving State
In this exercise, you'll be doing two things. First, creating a click listener inside the BodyPartFragment class that will update the image resource on a click! Second, you'll be adding some simple code to save the current state of the fragment -- this is so that the image that is being displayed is saved and will still be displayed when an activity restarts, such as on an orientation change.
Exercise Code
Exercise: TFragments.03-Exercise-ClicksAndSavingState
Saving state
To save the state of a fragment, you'll need to override the onSaveInstanceState method as well as check if there is a saved state, in the host activity, before creating new fragment instances.
Task Description:
Follow along with the list of tasks to complete the exercise.